<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    a {
        font-size: 30px;
        text-decoration: none;
    }

    html,body
     {
        width: 100%;
        height: 100%;
    }

    .yin {
        display: none;
        
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, .3);
    }

    .tan {
        display: none;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%);
        z-index: 10;
        width: 300px;
        height: 300px;
        background-color: red;
        border: 1px solid black;
    }
</style>

<body>
    <a href="#">注册</a>
    <div class="yin"></div>
    <div class="tan"></div>
</body>
<script>
    var aaa = document.querySelector('a')
    var yin = document.querySelector('.yin')
    var tan = document.querySelector('.tan')

    aaa.onclick = function (event) {
        event = event || window.event
        yin.style.display = 'block'
        tan.style.display = 'block'
        if (event.stopPropagation) {
            event.stopPropagation()
        } else {
            event.cancelBubble = true
        }
        document.onclick = function () {
            yin.style.display = 'none'
            tan.style.display = 'none'
        }

    }

</script>

</html>